// StoreEmployeeRelation.js

import { Util } from '../../utils/util.js';
import { Store } from './store.js';
import { Employee } from '../enterpriseMgt/employee.js';

export class StoreEmployeeRelation {
    constructor({ id = '', store = null, employee = null } = {}) {
        this.id = id;
        this.store = store;
        this.employee = employee;
        this.selected = false;
    }

    static clone(item) {
        return new StoreEmployeeRelation({
            id: item.id,
            store: item.store,
            employee: item.employee,
        });
    }

    static fromJson(json) {
        const id = Util.jsonToString(json.id);
        const store = Store.empty({
            id: Util.jsonToString(json.storeId),
            name: Util.jsonToString(json.storeName),
            publicStore: Util.jsonToBool(json.storeDefaultStore, false),
        });

        const employee = Employee.empty();
        employee.id = Util.jsonToString(json.employeeId);
        employee.name = Util.jsonToString(json.employeeName);

        return new StoreEmployeeRelation({ id, store, employee });
    }

    toJson() {
        return {
            id: this.id,
            employeeId: this.employee.id,
            storeId: this.store.id,
        };
    }

    toCopyJson() {
        return {
            id: this.id,

            storeId: this.store.id,
            storeName: this.store.name,
            storeDefaultStore: this.store.publicStore,

            employeeId: this.employee.id,
            employeeName: this.employee.name,

        };
    }
}
